package com.energyfuture.system.service.impl;

import com.energyfuture.system.api.model.SegmentEntity;
import com.energyfuture.system.api.model.SysparaEntity;
import com.energyfuture.system.config.ScheduledTask;
import com.energyfuture.system.mapper.SysIpsMapper;
import com.energyfuture.system.mapper.SysParamMapper;
import com.energyfuture.system.service.ISysParamService;
import com.energyfuture.system.service.ISysUserService;
import com.energyfuture.system.utils.ScheduleUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class SysParamServiceImpl implements ISysParamService {
    @Autowired
    private SysParamMapper sysParamMapper;

    @Autowired
    private SysIpsMapper sysIpsMapper;

    @Autowired
    private ISysParamService sysParamService;

    @Autowired
    private ISysUserService userService ;

    @Override
    public SysparaEntity selectParam() {
        return sysParamMapper.querySysParam();
    }

    @Override
    public int updateSysparam(SysparaEntity sysparaEntity) {

        int i = sysParamMapper.updateSysparam(sysparaEntity);
        if (i > 0 && sysparaEntity.getSearchcount() != null) {
            ScheduleUtils.reset(new ScheduledTask("task1",userService,sysParamService), sysparaEntity.getSearchcount());
        }
        return i;
    }

    @Override
    public List<SegmentEntity> ipList(SegmentEntity segmentEntity) {

        return sysIpsMapper.queryListByPage(segmentEntity);
    }

    @Override
    public int ipDelete(List<String> ips) {
        return sysIpsMapper.ipDelete(ips);
    }

    @Override
    public int ipUpdate(SegmentEntity segmentEntity) {

        return sysIpsMapper.ipUpdate(segmentEntity);
    }

    @Override
    public int ipInsert(SegmentEntity segmentEntity) {
        segmentEntity.setId(UUID.randomUUID().toString());
        return sysIpsMapper.ipInsert(segmentEntity);
    }

    @Override
    public SegmentEntity selectIpById(String id) {
        return sysIpsMapper.selectIpById(id);
    }


}
